package com.gitee.feizns.quickstart.ding.talk.api.v10.yida.processes.instances;

import com.aliyun.dingtalkyida_1_0.Client;
import com.aliyun.dingtalkyida_1_0.models.StartInstanceHeaders;
import com.aliyun.dingtalkyida_1_0.models.StartInstanceRequest;
import com.aliyun.dingtalkyida_1_0.models.StartInstanceResponse;
import com.aliyun.teautil.models.RuntimeOptions;
import com.gitee.feizns.quickstart.ding.talk.client.Clients;
import lombok.SneakyThrows;

/**
 * 发起宜搭审批流程
 * @author feizns
 * @since 2024/12/5
 */
public class Start {

    /**
     * 执行
     * @param accessToken 访问令牌
     * @param request 请求
     * @return {@link String}
     */
    @SneakyThrows
    public static String execute(String accessToken, StartInstanceRequest request) {
        Client client = Clients.get(Client.class);
        StartInstanceResponse resp = client.startInstanceWithOptions(request, headers(accessToken), new RuntimeOptions());
        return resp.getBody().getResult();
    }

    /**
     * 头
     * @param accessToken 访问令牌
     * @return {@link StartInstanceHeaders}
     */
    public static StartInstanceHeaders headers(String accessToken) {
        StartInstanceHeaders headers = new StartInstanceHeaders();
        headers.xAcsDingtalkAccessToken = accessToken;
        return headers;
    }

}
